from django.conf import settings
from django.shortcuts import render_to_response

from aptools import utils
from aptools.utils import http

def home(request):
   retval = None
   if request.method == 'GET':
      retval = render_to_response(settings.TEMPLATES['HOME'],
            utils.get_context(request, title = 'home'))
   else:
      retval = utils.aptools_error(request, utils.NOTALLOWED,
            error = "Invalid method %s requested" %request.metho)

   return retval

def rfc2893(request):
   if request.method == 'GET':
      retval = render_to_response(settings.TEMPLATES['RFC2893'],
            utils.get_context(request, title = 'RFC2893'))
   elif request.method == 'POST':
      print(request)
      retval = ssndb.Rfc2893.objects.using('ssn').all().values(
            'purpose', 'remote_mac_addr', 'remote_ipv4_addr',
            'remote_wan6_addr', 'remote_nan6_addr', 'local_ipv4_addr',
            'local_ipv6_addr', 'tunnel_index', 'crypto_index')
      retval = http.JSONResponse(retval)

   return retval
